home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
getwin1r
/
zoom.frm
< prev
Wrap
Text File
|
1999-09-07
|
12KB
|
391 lines
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
Begin VB.Form FormView
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = "View Picture With ZOOM"
ClientHeight = 3840
ClientLeft = 45
ClientTop = 615
ClientWidth = 4455
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 256
ScaleMode = 3 'Pixel
ScaleWidth = 297
StartUpPosition = 2 'CenterScreen
Begin MSComDlg.CommonDialog CommonDialog1
Left = 2040
Top = 1680
_ExtentX = 847
_ExtentY = 847
_Version = 327681
End
Begin VB.PictureBox Picture1
BackColor = &H80000010&
BorderStyle = 0 'None
Height = 3615
Left = 0
ScaleHeight = 241
ScaleMode = 3 'Pixel
ScaleWidth = 281
TabIndex = 2
Top = 0
Width = 4215
Begin VB.Image Image1
Enabled = 0 'False
Height = 1410
Left = 0
Stretch = -1 'True
Top = 0
Width = 1260
End
End
Begin VB.VScrollBar VScroll1
Height = 3615
Left = 4200
TabIndex = 1
Top = 0
Width = 255
End
Begin VB.HScrollBar HScroll1
Height = 255
Left = 0
TabIndex = 0
Top = 3600
Width = 4215
End
Begin VB.Image Image2
Height = 615
Left = 5040
Top = 840
Visible = 0 'False
Width = 615
End
Begin VB.Menu mnu_file
Caption = "&File"
Begin VB.Menu mnu_picture
Caption = "Open Picture"
End
Begin VB.Menu mnu_spacer
Caption = "-"
End
Begin VB.Menu mnu_exit
Caption = "E&xit"
End
End
End
Attribute VB_Name = "FormView"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim TX As Long
Dim TY As Long
Dim ZoomDepth As Long
Private Sub Form_Load()
'All computer screens (monitors) are NOT the same so
'we must account for that, and ensure that our
'software will work properly for every user.
'Below we set the TX and TY as the first piece of
'code to be executed.
'Our Form and PICTURE scalemodes are set at "3" or
'PIXEL, but when calculating measurements in VB
'we need to use their dimensions in PIXELS for
'easier calculation. Our scroll bars work better
'and quicker in pixels as opposed to TWIPS.
' My screen is 15 TWIPS per pixel, so
'TX and TY will actually equal 15 throughout the
'entire program. Your screen may be different.
TX = Screen.TwipsPerPixelX
TY = Screen.TwipsPerPixelY
End Sub
Private Sub HScroll1_Change()
HScroll1_Scroll
End Sub
Private Sub HScroll1_Scroll()
Image1.Left = -HScroll1.Value
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error GoTo BadZoom
'Here (button 1 / left mouse button), is where we zoom in
'on the picture
If Button = 1 Then
'I choose 10 as enough times for zooming in
'and you can change this to a higher or
'lower number if you want
If ZoomDepth >= 10 Then Beep: Exit Sub
'Notice the "Image1.Width / 4" that is used here. This merely
'increases the image by 25%. You may use a different number
'than "4" to change your zoom ratio, but make sure you use
'the same number through your code.
Image1.Width = Image1.Width + (Image1.Width / 4)
Image1.Height = Image1.Height + (Image1.Height / 4)
If Image1.Width < Picture1.Width Then
Image1.Left = 0
Else
'Else, everything seems to be good
'so we will zoom in as calculated below.
'NOTICE that this is where we maintain
'our "point of view". What I mean is,
'our mouse cursor is pointed at a specific
'area of the image, so when we zoom in, we
'want to see that same area at a closer view.
'The "X" in the code, directly below, is part
'of the calculation of the horizontal mouse
'positio, which in turn sets the scroll bar
'properly. Thus the image has shifted the
'correct amount.
Set_Scrolls
If HScroll1.Value + ((X / TX) / 4) > HScroll1.Max Then
'This "IF" statement makes sure that our scroll value
'does not exceed our Scroll MAX when zooming
'in near the far right of the image. If it does
'exceed, we will use the maximum scroll value
HScroll1.Value = HScroll1.Max
Else
HScroll1.Value = HScroll1.Value + ((X / TX) / 4)
End If
End If
'The "IF" statement below is the same
'as the one above, but it will now refer to the
'image height instead of the width
If Image1.Height < Picture1.Height Then
Else
Set_Scrolls
If VScroll1.Value + ((Y / TY) / 4) > VScroll1.Max Then
VScroll1.Value = VScroll1.Max
Else
VScroll1.Value = VScroll1.Value + ((Y / TY) / 4)
End If
End If
ZoomDepth = ZoomDepth + 1 'To keep track of how many times we soomed in
ElseIf Button = 2 Then 'Else if button 2 is clicked (right mouse).
'We will zoom out. The code below is
'very similar to the code above with
'some minor changes.
If Image1.Width <= 10 Then Beep: Exit Sub
If Image1.Height <= 10 Then Beep: Exit Sub
Image1.Width = Image1.Width - (Image1.Width / 4)
Image1.Height = Image1.Height - (Image1.Height / 4)
If Image1.Width < Picture1.Width Then
'Do nothing
Else
If HScroll1.Value - ((X / TX) / 4) > HScroll1.Max Then
HScroll1.Value = HScroll1.Max
ElseIf HScroll1.Value - ((X / TX) / 4) < 1 Then
HScroll1.Value = 1
Else
HScroll1.Value = HScroll1.Value - ((X / TX) / 4)
End If
End If
If Image1.Height < Picture1.Height Then
Image1.Top = 0
Else
If VScroll1.Value - ((Y / TY) / 4) > VScroll1.Max Then
VScroll1.Value = VScroll1.Max
ElseIf VScroll1.Value - ((Y / TY) / 4) < 1 Then
VScroll1.Value = 1
Else
VScroll1.Value = VScroll1.Value - ((Y / TY) / 4)
End If
End If
ZoomDepth = ZoomDepth - 1 'Deduct each time we zoom out
End If
Set_Scrolls 'Jump to the "Set_Scrolls Sub" here
'which will determine when to enable
'or disable a scroll bar.
Exit Sub
BadZoom:
Resume Next
End Sub
Private Sub mnu_2_Click()
End Sub
Private Sub mnu_exit_Click()
End
End Sub
Private Sub mnu_picture_Click()